<?php
/**
 * 做验证码及一些验证机制
 */
class ProofHelper
{
	/**
	 * 比较验证码与输入结果是否相符
	 * @return bool
	 */
	public static function compare($input, $key='img-proof-str') {
		return 0===strcasecmp($input, $_SESSION[$key]);
	}

	/**
	 * 生成并显示一个图片验证码
	 */
	public static function draw($key='img-proof-str', $style=null) {
		$_SESSION[$key] = self::makeText();
		ImageHelper::proof($_SESSION[$key], 26);
	}

	public static function clear($key='img-proof-str'){
		unset($_SESSION[$key]);
	}

	private static function makeText($length=5) {
		$str = 'abcdefghijkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXY34567891';
		$len = strlen($str)-1;
		$res = '';
		for($i=0;$i<$length;$i++){
			$res .= $str[mt_rand(0,$len)];
		}
		return $res;
	}

}
?>
